package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.basedoc.model.DriverInfo;
import com.eling.elcms.basedoc.model.PersonalInfo;
import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.travel.model.Driver;
import com.eling.elcms.travel.service.IDriverManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class DriverController extends BaseFormController {

	
	@Autowired
	private IDriverManager driverManager;
	
	
	@RequestMapping("/api/driverfile/saveDriver")
	@ResponseBody //String name,String idNumber,String address,String phone,Date birthday,Date driveBookDate,DriveBookType driveBookType
	public Driver saveDriver(@ModelAttribute @ModelFilling Driver driver,PersonalInfo personalInfo,DriverInfo driverInfo ){
		return driverManager.saveDriver(driver,personalInfo,driverInfo);
	}
	@RequestMapping("/api/driverfile/save")
	@ResponseBody
	public Driver save(@ModelAttribute @ModelFilling Driver driver ){
		return driverManager.save(driver);
	}
	
	@RequestMapping("/api/driverfile/{pkDriver}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkDriver){
		driverManager.remove(pkDriver);
		return new Msg("删除成功");
	}
	
	@RequestMapping("/api/driverfile/query")
	@ResponseBody
	public List<Driver> query(@ModelAttribute Driver cond){
		List<Driver> query = driverManager.query(cond);
		return query;
	}
	
	@RequestMapping("/api/driverfile/search*")
	@ResponseBody
	public List<Driver> search(@ModelAttribute SearchCondition sc,@ModelAttribute Driver driverfile ){
		sc.setQueryCondition(driverfile);
		return driverManager.search(sc);
	}
	
}
